package com.pzj.dormitory.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pzj.dormitory.entity.SystemAdmin;
import com.pzj.dormitory.mapper.SystemAdminMapper;
import com.pzj.dormitory.service.SystemAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzj.dormitory.vo.ResultVO;
import com.pzj.dormitory.form.RuleForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author admin
 * @since 2024-04-28
 */
@Service
public class SystemAdminServiceImpl extends ServiceImpl<SystemAdminMapper, SystemAdmin> implements SystemAdminService {


    @Autowired
    private SystemAdminMapper systemAdminMapper;
    @Override
    public ResultVO login(RuleForm ruleForm) {
        ResultVO<Object> resultVo = new ResultVO<>();
        // 1.判断用户名是否存在
        QueryWrapper<SystemAdmin> systemAdminQueryWrapper = new QueryWrapper<>();
        systemAdminQueryWrapper.eq("username",ruleForm.getUsername());
        SystemAdmin systemAdmin = systemAdminMapper.selectOne(systemAdminQueryWrapper);
        if (systemAdmin == null){
            resultVo.setCode(-1);
        }else {
            if (!systemAdmin.getPassword().equals(ruleForm.getPassword())) {
                resultVo.setCode(-2);

            } else {
                resultVo.setCode(0);
                resultVo.setData(systemAdmin);
            }
        }
        return resultVo;
    }
}
